import instance from '@/utils/axios'

//1.获取频道列表
const getTabls = () => {
  return instance({
    url: '/v1_0/user/channels',
    method: 'get'
  })
}

const getArticles = ({ channel_id, timestamp }) => {
  return instance({
    url: '/v1_1/articles',
    method: 'get',
    params: {
      with_top: 1, //是否需要置顶，给1即可
      channel_id,
      timestamp
    }
  })
}

// 新闻列表
const getArticleInfo = ({ id }) => {
  return instance({
    url: '/v1_0/articles/' + id,
    method: 'get'
  })
}

// 关注用户
const followUser = ({ target }) => {
  return instance({
    url: '/v1_0/user/followings',
    method: 'post',
    data: { target }
  })
}

// 取消关注
const noFollowUser = ({ target }) => {
  return instance({
    url: '/v1_0/user/followings/' + target,
    method: 'delete',
  })
}

// // 点赞
const articleLink = ({ target }) => {
  return instance({
    url: '/v1_0/article/likings',
    method: 'post',
    data: { target }
  })
}

// // 取消点赞
const noArticleLink = ({ target }) => {
  return instance({
    url: '/v1_0/article/likings/' + target,
    method: 'delete'
  })
}

// 搜索推荐词
const searchInput = keyword => {
  return instance({
    url: '/v1_0/suggestion',
    method: 'get',
    params: {
      q: keyword
    }
  })
}

// 搜索列表
const getSearchList = params => {
  return instance({
    url:'/v1_0/search',
    method:'get',
    params
  })
}

// 搜索历史记录
const searchLiShi = () => {
  return instance({
    url:'/v1_0/search/histories',
    method:'get'
  })
}

// 删除历史记录
const delSearchList = () => {
  return instance({
    url:'/v1_0/search/histories',
    method:'delete'
  })
}

export { getTabls }
export { getArticles }
export { getArticleInfo }
export { followUser }
export { noFollowUser }
export { articleLink }
export { noArticleLink }
export { searchInput }
export{getSearchList}
export {searchLiShi}
export {delSearchList}
